import { Injectable, OnModuleInit } from "@nestjs/common";
import AppConfig from "../../config/app.config";
import * as ws from 'ws';
@Injectable()
export class WebSocketClient implements OnModuleInit {
    public socketClient: any

    constructor() {
        this.socketClient = new ws(AppConfig.WsUrl);
    }
    onModuleInit() {
        this.registerConsumerEvent()
    }
    private registerConsumerEvent() {
        this.socketClient.on('open', () => {
            console.log('--------------open')
        })
        this.socketClient.on('error', (e) => {
            console.log('--------------error', e)
        })
        this.socketClient.on('message', (payload) => {
            const buf = Buffer.from(payload);
            const message = buf.toString('utf-8')
            // console.log(message)
        })
    }
}
